<?php
//error_reporting(0);
require_once ('library/googleresponse.php');
//require_once('library/googlemerchantcalculations.php');require_once ('library/googleresult.php');
require_once ('library/googlelog.php');
require_once ('library/googlerequest.php');
require_once ('includes/constants.php');
require_once ('includes/common.php');

$merchant_id = GOOGLE_MERCHANT_ID;
$merchant_key = GOOGLE_MERCHANT_KEY;
$server_type = "sandbox";
$currency = 'GBP';

extract($_REQUEST);
session_start();
$selectedOrders = null;

if (isset ($_REQUEST['bulk']) && $_REQUEST['bulk'] == 'true') {
	$selectedOrders = $_SESSION[ORDERS];
} else {
	$selectedOrders[0] = $_SESSION[ORDERS][$selectedOrder];
}

$Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency);

foreach ($selectedOrders as $orderData) {
	$orderID = $orderData['o_order_id'];
	$Grequest->SendChargeOrder($orderID);
}
//session_destroy();
//session_unregister(ORDERS); 
//header( 'Location: http://localhost/MTM_admin/manageOrders.php?operation=charged' ) ;

//header( 'Refresh: 0; url=http://localhost/MTM_admin/manageOrders.php?operation=charged' );

	$confirmationMessage = "Commands have been sent to Google Checkout to charge the order(s)." ;
	header( 'Location: confirmationPage.php?' . "confirmationMessage=" .$confirmationMessage) ;
	
	

?>
